# 第一步：构建前端代码
FROM node:16 as builder
WORKDIR /app
 COPY frontend/package*.json ./
 RUN npm install
 COPY frontend/ .
 # 运行前端单元测试并构建
RUN npm test && npm run build
# 第二步：运行前端（用Nginx）
FROM nginx:alpine
# 从构建阶段复制构建结果到Nginx
COPY --from=builder /app/dist /usr/share/nginx/html
 # 暴露80端口
EXPOSE 80
 CMD ["nginx", "-g", "daemon off;"]